my_list = [3,"apple",9,"banana",7,"cherry",2,"data",5,"elderberry"]
print("初始列表：",my_list)
my_list.append("fig")
print("\n1.添加fig后:",my_list)
my_list.remove("banana")
print("2.删除banana后:",my_list)
my_list[my_list.index(7)] = "grape"
print("3.将7改为geape后：",my_list)
cherry_index = my_list.index("cherry")
print("4.'cherry'的索引值:",cherry_index)
print("5.遍历列表元素：")
for item in my_list:
    print (item,end = " ")
print( )
my_list.insert(cherry_index + 1,"kiwi")
print("6.插入后：",my_list)
print("7.第三个元素:",my_list[2])
print("8.倒数第二个元素:",my_list[-2])
slice_2_to_6= my_list[2:7]
print("9.第三到七个元素：",slice_2_to_6)
reversed_list = my_list[::-1]
print("10。反转后的列表：",reversed_list)
strings = [(i,val) for i, val in enumerate(my_list) if isinstance(val,str)]
sorted_strings = [val for i, val in sorted(strings, key=lambda x: x[1])]
for idx, (i,_) in  (strings):
    my_list[i] = sorted_strings[idx]
print("11.字符串排序后",my_list)
number_map={
    0:'zero',1:'one',2:'two',3:'three',4:'four',
    5:'five',6:'six',7:'seven',8:'eight',9:'nine',
}
for i in range(len(my_list)):
    if isinstance(my_list[i],int) and my_list[i] in number_map:
        my_list[i] = number_map[my_list[i]]
print("12.数字替换为字符串",my_list)